package com.ds.infra.rpc.example.consumer.client;

import com.ds.infra.rpc.annotation.RpcReference;
import com.ds.infra.rpc.example.api.ProductService;
import org.springframework.stereotype.Component;

@Component
public class ProductClient {

    public ProductClient() {
        System.out.println("=======ProductClient initialized!");
    }
    @RpcReference(version = "1.0"/*, group = "product"*/)
    ProductService productService;

    public ProductService getProductService() {
        return this.productService;
    }

    public boolean reduceStock(Long productId, int quantity) {
        try {
            return productService.reduceStock(productId, quantity);
        } catch (Exception e) {
            throw new RuntimeException("调用商品服务失败", e);
        }
    }
}
